import sys
# ACM 模式下，通常推荐使用 sys.stdin.readline 来读取，因为它比 input() 稍快。
import heapq
def shortestTimeToEvacuate(grid: list[list[int]]) -> int:
    # ... 你的 Dijkstra 算法实现部分 ...
    n = len(grid)
    min_max_altitude = [[float('inf')] * n for _ in range(n)]
    pq = []
    min_max_altitude[0][0] = grid[0][0]
    heapq.heappush(pq, (grid[0][0], 0, 0))
    dr = [-1, 1, 0, 0]
    dc = [0, 0, -1, 1]

    while pq:
        current_max_t, r, c = heapq.heappop(pq)

        if current_max_t > min_max_altitude[r][c]:
            continue

        if r == n - 1 and c == n - 1:
            return current_max_t

        for i in range(4):
            nr, nc = r + dr[i], c + dc[i]

            if 0 <= nr < n and 0 <= nc < n:
                new_max_t = max(current_max_t, grid[nr][nc])

                if new_max_t < min_max_altitude[nr][nc]:
                    min_max_altitude[nr][nc] = new_max_t
                    heapq.heappush(pq, (new_max_t, nr, nc))

    return -1

# --- ACM 模式下的输入读取 ---
# 读取 N
# sys.stdin.readline().strip() 用于读取一行并去除末尾的换行符
N = int(sys.stdin.readline().strip())
# 创建 grid
grid = []
for _ in range(N):
    # 读取一行字符串，然后用 split() 按空格分割成字符串列表
    # 再用 map(int, ...) 将每个字符串转换为整数
    row = list(map(int, sys.stdin.readline().strip().split()))
    grid.append(row)
# 调用函数并输出结果
result = shortestTimeToEvacuate(grid)
print(result)

